<!-- 正文开始 -->
<style>
    .layui-tree-iconClick .layui-icon-file{
        display: none;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 数据表格 -->
            <table id="authRuleTable" lay-filter="authRuleTable"></table>
        </div>
    </div>
</div>
<!-- 表格操作列 -->
<!-- 表单弹窗 -->
<script type="text/html" id="ruleEditState">
    <input type="checkbox" lay-filter="tbStateCk" value="{{d.id}}" lay-skin="switch"
           lay-text="正常|锁定" {{d.status==1?'checked':''}}/>
</script>
<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'tableX', 'treeTable', 'admin', 'setter', 'dropdown', 'zTree','notice'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var treeTable = layui.treeTable;
        var admin = layui.admin;
        var setter = layui.setter;
        var notice = layui.notice;
        var tbDataList = [];  // 表格全部数据
        /* 渲染表格 */
        var insTb = treeTable.render({
            elem: '#authRuleTable',
            text: {
                none: '暂无相关数据'
            },
            tree: {
                iconIndex: 2,
                idName: 'id',
                pidName: 'parent_id',
                isPidData: true,
                getIcon: ''
            },
            height: 'full-170',
            defaultToolbar: '',
            cols: [[
                {field: 'id', title: '#', width: 60, align:'center'},
                {
                    title: '图标', templet: '<p><i class="layui-icon layui-icon-{{d.icon}}"></i></p>',
                    align: 'left', width: 60, minWidth: 60
                },
                {field: 'title', title: '菜单名称', align:'left'},
                {field: 'path', title: '路由标识', align:'left'},
                {field: 'sort', title: '排序', align:'center'},
            ]],
            reqData: function (data, callback, where) {
                admin.req(setter.baseServer + '/get_menu_list', function (res) {
                    tbDataList = res.data ? res.data : [];
                    for (var i = 0; i < tbDataList.length; i++) {
                        tbDataList[i].open = true;
                    }
                    callback(tbDataList);
                });
            }
        });


        /* 修改数据状态 */
        form.on('switch(tbStateCk)', function (obj) {
            notice.msg('加载中...', {icon: 4});
            var data = {};
            data.id = obj.elem.value;
            data.status = obj.elem.checked ? 1 : 0;
            admin.req(setter.baseServer + '/role_edit_status', data, function (res) {
                notice.destroy();
                if (200 === res.code) {
                    notice.msg(res.msg, {icon: 1});
                } else {
                    notice.msg(res.msg, {icon: 2});
                    $(obj.elem).prop('checked', !obj.elem.checked);
                    form.render('checkbox', $('#eDialogTable').next().attr('lay-filter'));
                }
            }, 'post');
        });
    });
</script>
